package com.chat.websocket.http;

import com.chat.websocket.domain.ChatInfoContainer;
import com.chat.websocket.domain.MemberInfo;
import com.google.gson.Gson;

import java.util.List;

/**
 * @author 崔超
 * 2022/2/18
 */
public class GetAllPerson implements BusinessFunc {
    @Override
    public String go(String... args) {
        if (args.length != 1) {
            return new Gson().toJson(
                    new ResponseMsg(false, null, "参数不对"));
        }
        String roomName = args[0];

        List<MemberInfo> personsInRoom = ChatInfoContainer.getPersonsInRoom(roomName);
        return new Gson().toJson(
                new ResponseMsg(true, personsInRoom, ""));
    }

    public static class ResponseMsg extends Response {
        public List<MemberInfo> persons;

        public ResponseMsg(boolean success, List<MemberInfo> persons, String msg) {
            super(success, msg);
            this.persons = persons;
        }
    }
}
